const mongoose = require("mongoose");

const Ques = require("../models/examination");

let options = {
  useNewUrlParser: true,
  useFindAndModify: false,
  useCreateIndex: true,
  autoIndex: false
};

mongoose.connect("mongodb://book:ABABcdcd1212@106.12.140.35/book", options);
mongoose.connection
  .on("open", () => {
    console.log("MongoDB Connected!");
  })
  .on("error", console.error);

const models = require("../question.js");
const question = models.pages[0].questions;

question.map(item => {
  let an = [];
  item.options.map(it => {
    an.push({
      id: it.id,
      text: it.text
      
    });
  });
  let res = new Ques({
    id: item.id,
    type: item.type,
    title: item.title,
    options: an
  }).save();

  console.log(item.id, item.title);
  console.log(item.options.map(it => console.log("答案:", it.id, it.text)));
});
